﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Biblioteca.Utils;
using System.Data.Common;
using System.Data;

namespace SERIX
{
    public partial class Indicadores : Seguranca
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            base.OnLoad(e);
            btnNovo.Enabled = PermissaoManut.Equals(Constantes.PERM_MANUTENCAO); 
        }

        protected void odsClasses_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
        {
            e.InputParameters["login"] = this.UsuAut.Login;
        }

        protected void btnNovo_Click(object sender, EventArgs e)
        {
            Response.Redirect("IndicadoresManut.aspx?OP=I");
        }

        protected void btnPequisar_Click(object sender, EventArgs e)
        {

        }

        protected void gridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string IDT = ((DataRowView)e.Row.DataItem)["IDT_IND"].ToString();

                //Se tiver permissao de Manutenção
                string medida, medida2, medida3;
                CMedidasIndicadores.MedidaIndicador(IDT, this.UsuAut.Login, out medida, out medida2, out medida3);
                ((HyperLink)e.Row.Cells[gridView.Columns.Count - 6].Controls[1]).Text = medida;
                ((HyperLink)e.Row.Cells[gridView.Columns.Count - 5].Controls[1]).Text = medida2;
                ((HyperLink)e.Row.Cells[gridView.Columns.Count - 4].Controls[1]).Text = medida3;


                ((HyperLink)e.Row.Cells[gridView.Columns.Count - 6].Controls[1]).NavigateUrl = "MedidasIndicadores.aspx?OP=U&idt=" + Server.UrlEncode(Criptografia.Criptografar(IDT));
                ((HyperLink)e.Row.Cells[gridView.Columns.Count - 5].Controls[1]).NavigateUrl = "MedidasIndicadores.aspx?OP=U&idt=" + Server.UrlEncode(Criptografia.Criptografar(IDT));
                ((HyperLink)e.Row.Cells[gridView.Columns.Count - 4].Controls[1]).NavigateUrl = "MedidasIndicadores.aspx?OP=U&idt=" + Server.UrlEncode(Criptografia.Criptografar(IDT));
                ((HyperLink)e.Row.Cells[gridView.Columns.Count - 3].Controls[1]).NavigateUrl = "IndicadoresManut.aspx?OP=R&idt=" + Server.UrlEncode(Criptografia.Criptografar(IDT));
                ((HyperLink)e.Row.Cells[gridView.Columns.Count - 2].Controls[1]).NavigateUrl = "IndicadoresManut.aspx?OP=U&idt=" + Server.UrlEncode(Criptografia.Criptografar(IDT));
                ((HyperLink)e.Row.Cells[gridView.Columns.Count - 1].Controls[1]).NavigateUrl = "IndicadoresManut.aspx?OP=D&idt=" + Server.UrlEncode(Criptografia.Criptografar(IDT));

                //SEGURANÇA
                ((HyperLink)e.Row.Cells[gridView.Columns.Count - 6].Controls[1]).Enabled = !PermissaoManut.Equals(Constantes.PERM_NEGADA);
                ((HyperLink)e.Row.Cells[gridView.Columns.Count - 5].Controls[1]).Enabled = !PermissaoManut.Equals(Constantes.PERM_NEGADA);
                ((HyperLink)e.Row.Cells[gridView.Columns.Count - 4].Controls[1]).Enabled = !PermissaoManut.Equals(Constantes.PERM_NEGADA);
                ((HyperLink)e.Row.Cells[gridView.Columns.Count - 3].Controls[1]).Enabled = !PermissaoManut.Equals(Constantes.PERM_NEGADA);
                ((HyperLink)e.Row.Cells[gridView.Columns.Count - 2].Controls[1]).Enabled = PermissaoManut.Equals(Constantes.PERM_MANUTENCAO);
                ((HyperLink)e.Row.Cells[gridView.Columns.Count - 1].Controls[1]).Enabled = PermissaoManut.Equals(Constantes.PERM_MANUTENCAO);

            }
        }

        protected void odsIndicadores_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
        {
            e.InputParameters["login"] = this.UsuAut.Login;
        }
    }
}
